const userInfo = sessionStorage.userInfo ? JSON.parse(sessionStorage.userInfo) : {};
const user = {
  state: {
    info: userInfo,
    status: '',
    code: '',
    token: userInfo.token,
    name: userInfo.userAccount,
    menus: userInfo.menus,
    permissions: userInfo.permissions,
    orgInfo: {},
    setting: {
      articlePlatform: []
    }
  },

  mutations: {
    SET_USER_INFO: (state, userInfo) => {
      state.info = userInfo
    },
    SET_TOKEN: (state, token) => {
      state.token = token
    },
    SET_SETTING: (state, setting) => {
      state.setting = setting
    },
    SET_STATUS: (state, status) => {
      state.status = status
    },
    SET_NAME: (state, name) => {
      state.name = name
    },
    SET_MENUS: (state, menus) => {
      state.menus = menus
    },
    SET_PERMISSIONS: (state, permissions) => {
      state.permissions = permissions
    },
    SET_ORG_INFO: (state, orgInfo) => {
      state.orgInfo = orgInfo
    }
  },

  actions: {
    // 登出
    logOut({ commit, state }) {
      return new Promise((resolve, reject) => {
        sessionStorage.setItem('userInfo', '');
        commit('SET_USER_INFO', '')
        commit('SET_TOKEN', '')
        commit('SET_MENUS', [])
        commit('SET_NAME', '')
        commit('SET_PERMISSIONS', [])
        resolve()
      })
    }
  }
}

export default user
